package com.wanxi.servlet;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.*;
import com.wanxi.service.CompanyService;
import com.wanxi.service.NavService;
import com.wanxi.service.NewsService;
import com.wanxi.service.ProductService;
import com.wanxi.service.impl.CompanyServiceImpl;
import com.wanxi.service.impl.NavServiceImpl;
import com.wanxi.service.impl.NewsServcieImpl;
import com.wanxi.service.impl.ProductServiceImpl;
import com.wanxi.util.PageEnum;
import com.wanxi.util.WhereShowEnum;
import com.wanxi.vo.HomeVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/common")
public class CommonServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //        1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.拿到前端的值

//        3.封装VO
        HomeVO homeVO = new HomeVO();
//        4.调用service
        CompanyService companyService = new CompanyServiceImpl();
        NavService navService = new NavServiceImpl();
//        5.得到返回值
        CompanyDTO companyDTO = companyService.find(homeVO);
        List<NavDTO> navDTOList = navService.find(homeVO);
        HomeDTO homeDTO = new HomeDTO();
        homeDTO.setCompanyDTO(companyDTO);
        homeDTO.setNavDTO(navDTOList);
//        6.返回给前端
        resp.getWriter().println(JSONObject.toJSONString(homeDTO));

    }
}
